<template>
  <div class="app-container">
    <div class="search">
      <el-form ref="form" :model="form" label-width="80px" inline>
        <!-- <el-form-item label="">
          <el-select v-model="form.region" placeholder="操作类型">
            <el-option label="未启用" value="shanghai"></el-option>
            <el-option label="已启用" value="beijing"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="">
          <el-date-picker
            v-model="form.operTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="操作时间"
          />
        </el-form-item>
        <el-form-item label="">
          <el-input v-model="form.operIp" placeholder="IP地址" />
        </el-form-item>
        <el-form-item label="">
          <el-input v-model="form.createBy" placeholder="用户名称" />
        </el-form-item>
        <el-form-item label="">
          <el-button size="mini" icon="el-icon-search" @click="search"
            >查询</el-button
          >
          <el-button size="mini" icon="el-icon-refresh-right" @click="search(1)"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      element-loading-text="加载中"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="操作类型">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="操作时间" width="170" align="center">
        <template slot-scope="scope">
          {{ scope.row.operTime }}
        </template>
      </el-table-column>
      <el-table-column label="IP地址" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.operIp }}</span>
        </template>
      </el-table-column>
      <el-table-column label="字典参数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.operParam }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行结果" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.jsonResult }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户名称" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createBy }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { monitorList } from "@/api/table";

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      form: {},
      list: null,
      currentPage: 1,
      pageNum: 10,
      total: 0,
      listLoading: true,
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    deleteRow() {
      removeUser({
        ids: this.multipleSelection.map((item) => item.userId).join(","),
      }).then((res) => {
        console.log(res);
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.pageNum = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.fetchData();
    },
    search(num) {
      if (num == 1) {
        this.form = {};
      }
      this.currentPage = 1;
      this.fetchData();
    },
    fetchData() {
      this.listLoading = true;
      monitorList({
        pageSize: this.pageNum,
        pageNum: this.currentPage,
        ...this.form,
      }).then((res) => {
        this.list = res.rows;
        this.listLoading = false;
        this.total = res.total;
      });
    },
  },
};
</script>
